import { Component } from "react"
/**
 * 父组件
 */
class App extends Component {
  state = {
    // 把兄弟组件都想要的数据定义到父组件中
    work: {
      name: 'baidu'
    },
    changeMsg: (msg) => {
      this.setState({
        work: { name: msg }
      })
    }
  }
  render () {
    return (
      <div>
        <h1>父组件</h1>
        <Bro1 changework={this.state.changeMsg} work={this.state.work}></Bro1>
        <Bro2 work={this.state.work} ></Bro2>
      </div>
    )
  }
}
class Bro1 extends Component {
  render () {
    return (
      <div>
        <h2>哥哥</h2>
        <button onClick={() => { this.props.changework('zijie') }}>改变工作</button>
      </div >
    )
  }
}
function Bro2 (props) {
  return (
    <div>
      <h2>弟弟{props.work.name}</h2>
    </div>
  )
}
export default App